<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../style/fjol_style.css" rel="stylesheet" />
	</head>

	<body>
		<div id="pullrefresh" class="mui-scroll-wrapper">
		    <div class="mui-scroll">
		        <!--这里放置真实显示的DOM内容-->
		        <ul class="mui-table-view" id="selleHouseList">
		            
		        </ul>
		    </div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-2.1.0.js"></script>
		<script src="../js/jquery.tmpl.min.js"></script>
		<script src="../js/md5.js"></script>
		<script src="js/common.util.js"></script>
		<script src="../js/network.js"></script>
		<script id="selleHouseTmpl" type="text/x-jquery-tmpl">
			<li class="mui-table-view-cell" id="${id}">
				<a class="mui-navigate-right" style="padding-right:20px;">
                    <img class="mui-pull-left mr5" width="100" height="80" src="${coverImage}">
                    <div class="mui-media-body">
                        <span class="mui-badge mui-badge-success mui-badge-inverted f10">[${statusName}]</span>(${area})${buildingName}${buildNumber}-${number}
                        <div class="mui-ellipsis mui-clearfix mt10">
                        	<span class="mui-badge mui-badge-success mui-badge-inverted f14 mui-pull-right">${parseInt(totalPrice/10000)}万</span>
                        	<div>
                        		<p>
                        			<span class="mui-badge mui-badge-success mui-badge-inverted f10">${collectionTotal}</span>人关注
                        			<span class="mui-badge mui-badge-success mui-badge-inverted f10">${bargainTotal}</span>次砍价
                        		</p>
                        		<p class="mui-inline">最新交易进度：</p><span class="f08">${$item.getTradingStateName()}</span>
                        	</div>
                        </div>
                    </div>
				</a>
		    </li>
		</script>
		<script type="text/javascript">
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			
			var pagevalue = 1;
			function pulldownRefresh(){
				setTimeout(function(){
					$('.mui-pull').hide();
					
					getSelleHouse(1,10,true);
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
				 	mui('#pullrefresh').pullRefresh().enablePullupToRefresh();
					return pagevalue = 1;
				},1000);
			}
			function pullupRefresh(){
				$('.mui-pull').show();
				setTimeout(function(){
					pagevalue++;
					getSelleHouse(pagevalue,10,false);
				},1000);
				
			}
			mui.plusReady(function(){
				getSelleHouse(1,10,false);
			});
			function getSelleHouse(pagevalue,rowsvalue,isTrue){
				
					var userInfo = common.myStorage.getItem('userInfo');
					var param = [{
						key:'clientId',
						value:userInfo.clientId
					},{
						key:'page',
						value:pagevalue
					},{
						key:'rows',
						value:rowsvalue
					}];
				fjNetwork.get('fjzx/client/my-house-list.json',param,function(data){
//					console.log(JSON.stringify(data));
					var rows = data.rows;
					if(isTrue){
						document.querySelector('#selleHouseList').innerHTML = '';
					}
					
					$('#selleHouseTmpl').tmpl(rows,{
						getTradingStateName:function(){
							var tradingStateName = this.data.tradingStateName;
							if(tradingStateName){
								return tradingStateName;
							}else{
								return '暂无';
							}
						}
					}).appendTo('#selleHouseList');
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(rows.length==0);
					
					mui('#selleHouseList li').each(function(){
						this.addEventListener('tap',function(){
//							console.log(this.getAttribute('id'));
							mui.openWindow({
								url:'../house_detail.html',
								id:'house_detail',
								extras:{
									houseId:this.getAttribute('id')
								}
							})
						});
					});
				},function(msg){
					console.log(msg);
				});
			}
		</script>
	</body>

</html>